// 用来生成全局组件这里用来注册全局的loading
import Vue from 'vue'
import Loading from './loading/loading'

const CreateLoading = Vue.extend(Loading) // 注册组件

const instence = new CreateLoading({
    el: document.createElement('div')
})
// console.log(instence)
instence.show = false // 用来记录loading是否显示

const $loading = {
    show(msg) {
        instence.show = true
        instence.msg = msg
        document.body.appendChild(instence.$el)
    },

    hide() {
        instence.show = false
    }
}

export default {
    install() {
        if(!Vue.$loading) {
            Vue.$loading = $loading
        }
        Vue.mixin({
            created() {
                this.$loading = Vue.$loading
            }
        })
    }
}
